package org.teremail.store;

import java.util.Iterator;

public class Strings {

    /**
     * Joins a collection using a delimiter.
     * 
     * @param os
     * @param d
     * @return
     */
    public static String join(Iterable<? extends Object> os, String d) {
        StringBuilder sb = new StringBuilder();
        for (Iterator<? extends Object> oIt = os.iterator(); oIt.hasNext();) {
            String s = String.valueOf(oIt.next());
            sb.append(s);
            if (oIt.hasNext()) {
                sb.append(d);
            }
        }
        return sb.toString();
    }

    /**
     * Joins a parameter list of strings using a delimiter.
     * 
     * @param d
     * @param os
     * @return
     */
    public static String join(String d, Object...os) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < os.length; i++) {
            String s = String.valueOf(os[i]);
            sb.append(s);
            if (i + 1 < os.length) {
                sb.append(d);
            }
        }
        return sb.toString();
    }
    
}
